import {reactive, ref} from 'vue'


const state = ref({
	userInfo: null
})
const getUserInfo = ()=> {
	const username = uni.getStorageSync('wpa_username');
	if(!username) return;
	uni.request({
		url: '/api/wallpaper/user/info',
		method: 'POST',
		data: {
			username
		}
	}).then(res=>{
		state.value.userInfo = res.data
	})
}

const updateUserInfo = (data) => {
		return uni.request({
			url: '/api/wallpaper/user/update',
			method: 'POST',
			data: {
				username: uni.getStorageSync('wpa_username'),
				...data
			}
		}).then((resp)=>{
			state.value.userInfo = resp.data
			return resp.data
		})
}

export default {
	state,
	getUserInfo,
	updateUserInfo
}